package org.jeecg.modules.company.webController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.query.QueryRuleEnum;
import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.company.entity.JkCompany;
import org.jeecg.modules.company.service.IJkCompanyService;
import org.jeecg.modules.util.DictUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Tag(name="前端jk_product企业接口")
@RestController
@RequestMapping("/api/company")
@Slf4j
public class JKCompanyWebController {

    @Autowired
    private IJkCompanyService jkCompanyService;

    @Autowired
    DictUtils dictUtils;
    /*
       查看企业列表
     */

    @Operation(summary="前端企业，公司-分页列表查询")
    @GetMapping(value = "/list")
    @IgnoreAuth
    public Result<IPage<JkCompany>> queryPageList(JkCompany jkCompany,
                                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {

        QueryWrapper<JkCompany> queryWrapper = QueryGenerator.initQueryWrapper(jkCompany, req.getParameterMap());
        queryWrapper.orderByAsc("sn");
        Page<JkCompany> page = new Page<JkCompany>(pageNo, pageSize);
        IPage<JkCompany> pageList = jkCompanyService.page(page, queryWrapper);
        return Result.OK(pageList);
    }



    @Operation(summary="前端企业，公司-通过id查询")
    @GetMapping(value = "/queryById")
    @IgnoreAuth
    public Result<JkCompany> queryById(@RequestParam(name="id",required=true) String id) {
        JkCompany jkCompany = jkCompanyService.getById(id);

        String patentField = dictUtils.getDictItemName("company_status",jkCompany.getStatus());
        jkCompany.setStatus(patentField);

        if(jkCompany==null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(jkCompany);
    }

}
